# -*- coding: utf-8 -*-

# @Author : guoxin

# @Time : 2024/3/26 15:45

# @QQ :363673234
from time import sleep

import psutil
import pytest
import allure
from common.report_add_img import add_img_2_report

from page.LoginPage import LoginPage


@pytest.mark.UImain
@pytest.mark.UIsomke
class TestLogin:
    def test_login(self, driver):
        """错误的登录"""
        with allure.step("登录"):
            LoginPage().login(driver, "guoxin1")
            sleep(3)
        with allure.step("断言"):
            assert LoginPage().login_assert(driver, "search.png") > 0.9
            add_img_2_report(driver, "登录")

    def kill_wbchrome_process():
        # 检查 Chrome 进程的命令行参数
        def is_webdriver_process(proc):
            cmd_args = proc.cmdline()
            for arg in cmd_args:
                if 'webdriver' in arg.lower():
                    return True
            return False

        # 获取所有 Chrome 进程
        chrome_processes = [proc for proc in psutil.process_iter() if proc.name().lower() == 'chrome.exe']
        # 遍历 Chrome 进程并杀死非用户态的进程
        for proc in chrome_processes:
            try:
                if is_webdriver_process(proc):
                    proc.kill()
                    print(f"Killed Chrome Process: {proc.pid}")
            except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
                pass
